package com.zhuoyue.biz.core.command.service.impl;

import com.zhuoyue.biz.core.api.service.GatewayRedisService;
import com.zhuoyue.biz.core.command.service.CmdSendService;
import com.zhuoyue.common.utils.CmdUtils;
import com.zhuoyue.common.utils.RandomUtil;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class CmdSendServiceImpl implements CmdSendService {
    @Autowired
    private GatewayRedisService gatewayRedisService;

    @Override
    public List<String> sendPsdSecretKeyToLock(String deviceMac, String gatewayMac) {

        String strHexRandom = RandomUtil.getStrHexRandom(4);
//        String strHexRandom = "1234";
        List<String> keys = new ArrayList<>();
        keys.add(StringUtils.substring(strHexRandom, 0, 2));
        keys.add(StringUtils.substring(strHexRandom, 2, 4));

        String cmd = "0201" + gatewayMac + deviceMac + "03FA" + "0C" + "06" + strHexRandom + "00000000";
        cmd = "2A" + CmdUtils.getDateLength(cmd) + cmd + CmdUtils.getCmdBodySum(cmd) + "23";
        gatewayRedisService.writeDataToGateway(gatewayMac, cmd);
        System.out.println("cmd = " + cmd);
        return keys;
    }


}
